﻿Imports System.Data.SqlClient

Partial Class add_category
    Inherits System.Web.UI.Page
    Dim cn As New SqlConnection(ConfigurationSettings.AppSettings("conn"))


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("username").ToString.ToLower() <> "admin" Then
            Response.Redirect("Default.aspx")
        End If
        Label2.Text = Session("username")

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim cmd As New SqlCommand("insert into category(name) values('" + TextBox1.Text.Trim() + "')", cn)
        Try
            cn.Open()
            If (cmd.ExecuteNonQuery = 1) Then
                Label3.Text = "New Category is added."
                TextBox1.Text = ""
            Else
                Label3.Text = "Problem occured !"
            End If
            cn.Close()
        Catch
        End Try
        Response.Redirect("add_Category.aspx")
    End Sub
End Class
